package com.bestcem.xm.txtanls.controller;

import com.bestcem.xm.component.security.annotation.AuthIgnore;
import com.bestcem.xm.txtanls.dao.mapper.JoinInfoViewpointMapper;
import com.bestcem.xm.txtanls.dao.mapper.TxtanlRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jy.zhao
 * @version 2022/2/24 18:28
 * @date 2021/8/5 17:19
 **/
@RestController
@RequestMapping("/txtanls/shard")
public class TxtanlsShardTableController {

    @Autowired
    TxtanlRecordMapper txtanlRecordMapper;

    @Autowired
    JoinInfoViewpointMapper joinInfoViewpointMapper;

    @GetMapping("/record_table_create/{count}")
    @AuthIgnore
    public String recordTableCreate( @PathVariable(value = "count") Integer count) {
        if(count <= 0) {
            return "创建表数量不能小于等于0";
        }
        for (int i = 0; i < count; i++) {
            String tableName = "ds_txtanls_record_" + i;
            txtanlRecordMapper.createNewTable(tableName);
        }
        return "success";
    }

    @GetMapping("/view_table_create/{count}")
    @AuthIgnore
    public String viewTableCreate( @PathVariable(value = "count") Integer count) {
        if(count <= 0) {
            return "创建表数量不能小于等于0";
        }
        for (int i = 0; i < count; i++) {
            String tableName = "ds_txtanls_join_info_viewpoint_" + i;
            joinInfoViewpointMapper.createNewTable(tableName);
        }
        return "success";
    }
}
